package koscom.corebase.main;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Run implements Runnable {

	MainScreen frame1;
	Login frame;
	Connect con;
	InputStream br;
	Date today;
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd   HH:mm:ss");
	String today1;
	byte[] buff=new byte[1024];
	
	public Run(MainScreen frame1, Login frame, Connect con){
		super();
		this.frame1=frame1;
		this.frame=frame;
		this.con=con;
		br=con.getInput();
	}
	
	static String parsing(byte[] buff,int start, int end){
		byte[] temp=new byte[end-start+1];
		for(int i=0;i<(end-start+1);i++){
			temp[i]=buff[start+i];
		}
		try{
			return new String(temp,"UTF-8");
		}catch(UnsupportedEncodingException e){
			e.printStackTrace();
			return null;
		}
	}
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
		while(true){
			try{
				//int cnt = br.read(buff);
				br.read(buff);
				if(parsing(buff,4,5).equals("OO")){
					MainScreen.frame.dispose();					
					MainScreen.window.CoreBase.setVisible(true);
					frame1.txtNotice.setText("   로그인 아이디 : "+parsing(buff,6,24).trim()+"       해당 지점명 : "+parsing(buff,25,45));
				}else if(parsing(buff,4,5).equals("XX")){
					Clear();
					frame.txtResult.setText("login failed");
				}
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}
	public void Clear(){
		frame.txtID.setText("");
		frame.txtPW.setText("");
	}
}
